<template>
	<view class="item-out" :style="'flex-wrap:'+wrap+';'">
		<view v-for="item in lists" :key="item.id" class="item" :style="'width:'+itemWidth+';'"
			@tap="goDetails(item.id)">
			<image :src="item.imgUrl" class="img" :style="'height:'+imgHeight+';'"></image>
			<view class="content">
				<text class="name">{{item.name}}</text>
				<view class="price">
					<text class="p1">￥{{item.price}}</text>
					<text class="p2">￥{{item.price}}</text>
				</view>
				<text class="discount">{{item.discount}}折</text>
			</view>
		</view>
	</view>
</template>

<script>
	/**
	 * @description: 单个商品
	 * @property {Array} lists 渲染数据
	 * @property {String} itemWidth 宽度
	 * @property {String} imgHeight 高度
	 * @property {String} wrap 单行数据是否分行
	 */
	export default {
		props: {
			lists: {
				type: Array,
				default: []
			},
			itemWidth: {
				type: String,
				default: "375rpx"
			},
			imgHeight: {
				type: String,
				default: "350rpx"
			},
			wrap: {
				type: String,
				default: "wrap"
			}
		},
		methods: {
			goDetails(id) {
				uni.navigateTo({
					url: '/pages/details/details?id=' + id + ''
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.item-out {
		display: flex;
		margin: 20rpx;
		justify-content: space-between;

		.item {
			padding-bottom: 20rpx;

			.img {
				width: inherit;
			}

			.content {
				text-align: center;

				.price {

					.p2 {
						color: #ccc;
						font-size: 30rpx;
						text-decoration: line-through;
					}

					.p1 {
						color: #333;
					}
				}

				.name {
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.discount {
					border-radius: 4rpx;
					padding: 2rpx 10rpx;
					font-size: 20rpx;
					color: red;
					border: solid 2px red;
				}
			}
		}
	}
</style>
